package com.zmn.uac.client;

import com.zmn.common.dto2.ResponseDTO;
import com.zmn.uac.UacException;
import com.zmn.uuc.common.constant.DubboConsts;
import com.zmn.uuc.common.dio.user.UserLoginByThirdDIO;
import com.zmn.uuc.dubbo.interfaces.user.UserLoginRemoteService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

/**
 * @title: 个人用户登录Dubbo接口
 * @author:Rananquan
 * @Date:2022/6/9 20:28
 */
@Slf4j
@Component
public class UserLoginClient {

    @DubboReference(version = DubboConsts.INTERFACE_VERSION, check = false)
    UserLoginRemoteService userLoginRemoteService;

    /**
     * 通过三方账号登录
     * @param dio
     * @return token
     */
    public String loginByThirdAccount(UserLoginByThirdDIO dio){
        log.info("通过三方账号登录入参：[{}]",dio);
        ResponseDTO<String> tokenResponse = userLoginRemoteService.loginByThirdAccount(dio);
        if(!tokenResponse.isSuccess()){
            log.error("通过三方账号登录请求失败，失败原因：{}", tokenResponse.getMessage());
            throw new UacException(tokenResponse.getMessage());
        }

        String token = tokenResponse.getData();
        log.info("通过三方账号登录返回response：{}",token);

        return token;
    }
}
